﻿using System.Collections.Generic;

using BodaNetCommunications.Nodes;

namespace BodaNetCommunications.ModbusTcpComs
{
    /// <summary>
    /// Modbus数据读取的组别，单独配置变量集合的读取方式和列表信息
    /// </summary>
    public class ModbusTCPGroup : BodaNodeClass
    {
        public List<ModbusTCPVariable> varList = new List<ModbusTCPVariable>();

        public ModbusStoreArea StoreArea { get; set; }

        public int Start { get; set; }

        public int Length { get; set; }

        public int SlaveID { get; set; }

        public string Type { get; set; }

        public bool IsActive { get; set; }

        public ModbusTCPGroup()
        {
            Name = "组对象";
            Description = "作为一次批量的线圈或寄存器数据读取";
            StoreArea = ModbusStoreArea.保持寄存器4XXXX_RW;
            SlaveID = 1;
            Start = 0;
            Length = 10;
            NodeType = 100;
            NodeHead = "ModbusGroup";
            Type = "ModbusTCP";
            IsActive = true;
        }

        public override List<BodaNodeClassRenderItem> GetNodeClassRenders()
        {
            List<BodaNodeClassRenderItem> nodeClassRenders = base.GetNodeClassRenders();
            nodeClassRenders.Add(new BodaNodeClassRenderItem("激活情况", IsActive ? "已激活" : "未激活"));
            nodeClassRenders.Add(new BodaNodeClassRenderItem("存储区", StoreArea.ToString()));
            nodeClassRenders.Add(new BodaNodeClassRenderItem("起始地址", Start.ToString()));
            nodeClassRenders.Add(new BodaNodeClassRenderItem("长度", Length.ToString()));
            nodeClassRenders.Add(new BodaNodeClassRenderItem("从站地址", SlaveID.ToString()));
            return nodeClassRenders;
        }
    }
}